package whu.cn.whushare.ui.main.my.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.androidplus.util.ViewMapping;
import com.androidplus.util.ViewMappingUtil;

import java.util.List;

import whu.cn.whushare.R;
import whu.cn.whushare.bean.User;
import whu.cn.whushare.common.ImageWorkerManager;
import whu.cn.whushare.ui.main.activity.bean.Activity;
import whu.cn.whushare.ui.main.activity.bean.AllActivity;
import whu.cn.whushare.ui.main.my.bean.MyActivity;
import whu.cn.whushare.util.Utils;

/**
 * Created by xiaoping on 2015/4/11.
 */
public class MyActivityListAdapter extends BaseAdapter {
    private MyActivity myActivity;
    private Context context;

    /**
     *
     * @param context
     *            mainActivity
     * @param myActivity
     *            显示的数据
     */
    public MyActivityListAdapter(Context context, MyActivity myActivity) {
        this.context = context;
        this.myActivity =myActivity;

    }

    /*
     * 获得数据总数
     */
    @Override
    public int getCount() {
        return myActivity.Activity.size();
    }

    /*
     * 根据索引为position的数据
     */
    @Override
    public Object getItem(int position) {
        return myActivity.Activity.get(position);
    }

    /*
     * 根据索引值获得Item的Id
     */
    @Override
    public long getItemId(int position) {
        return myActivity.ActivitySignCounts.get(position);
    }

    /*
     * 通过索引值position将数据映射到视图convertView具有缓存功能，在第一页时为null，在第二第三....页时不为null
     */
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.layout_my_activity_item, null);
            viewHolder = new ViewHolder();
            ViewMappingUtil.mapView(viewHolder, convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        Activity activity = myActivity.Activity.get(position);
        viewHolder.activity.setText(activity.getActivityName() + "");
        viewHolder.signCount.setText("报名人数："+myActivity.ActivitySignCounts.get(position)+ "");
        viewHolder.endTime.setText("报名截止日："+activity.getEndTime() + "");
        return convertView;
    }

    class ViewHolder {
        @ViewMapping(id = R.id.activity)
        private TextView activity;
        @ViewMapping(id = R.id.sign_count)
        private TextView signCount;
        @ViewMapping(id = R.id.end_time)
        private TextView endTime;
        @ViewMapping(id=R.id.my_activity_layout)
        private RelativeLayout myActivityLayout;


    }
}

